<template>
<div class="recycle-merchandise  views-container">
    <div class="wlm-table">
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.recycleTable.files" size="small" label-width="90px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="商品名称：">
                        <el-input v-model="tableFormatData.recycleTable.files.goods_name" placeholder="请输入商品名称" style="width:160px;"></el-input>
                    </el-form-item>
                    <el-form-item label="商品分类：">
                        <!-- <el-select v-model="tableFormatData.recycleTable.files.category_id" placeholder="请选择">
                            <el-option v-for="item in categoryData" :key="item.value" :label="item.name" :value="item.category_id">
                            </el-option>
                        </el-select> -->
                        <el-cascader :props="myProps" :options="categoryData" :show-all-levels="false" v-model="category_array" @change="categoryChange">
                        </el-cascader>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button v-waves type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">

            <el-table :ref="tableFormatData.recycleTable.key" :data="tableFormatData.recycleTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55" >
                </el-table-column>
                <el-table-column prop="date" label="商品图片" >
                    <template slot-scope="scope" v-if="scope.row.image[0]">
                        <img class="logo" :src="scope.row.image[0]['file_path']">
          </template>
                </el-table-column>
                <el-table-column prop="date" label="商品名称" >
                    <template slot-scope="scope">
                        <span>{{scope.row.goods_name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="商品分类" >
                    <template slot-scope="scope" v-if="scope.row.category_data">
                        <span v-for="(item, index) in scope.row.category_data" :key="index">{{`${item.name?`${item.name || ''}：${item.child.join('/')}`:`${item.child.join('/')}`}`}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="价格" >
                    <template slot-scope="scope">
                        <p v-if="scope.row.sku.length>0">{{ scope.row.sku[0].goods_price }}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="库存" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.sku.length>0">{{ scope.row.sku[0].stock_num }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="销量" >
                    <template slot-scope="scope">
                        <span>{{scope.row.goods_sales}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="删除时间" sortable >
                    <template slot-scope="scope">
                        <span>{{scope.row.update_time}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <el-button class="wlm-text" type="text" @click="changeTableItem({ids:[scope.row.goods_id]},tableFormatData.recycleTable.change.restore)">恢复</el-button>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.goods_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>

            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all"  true-label="1" false-label="0" v-model="tableFormatData.recycleTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" type="primary" :disabled="isGroup" size="mini" @click="changeTableItem({isGroup:true},tableFormatData.recycleTable.change.restore)">批量恢复</el-button>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.recycleTable.pagination.page" :page-sizes="tableFormatData.recycleTable.pagination.pagesizes" :page-size.sync="tableFormatData.recycleTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.recycleTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  categoryIndex,
  goodsRegainDel,
  goodsRecovery,
  goodsRegain
} from '@/api/merchandise'

import waves from '@/directive/waves' // Waves directive
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'RecyclePlatform',
  components: {

  },
  directives: {
    waves
  },
  created() {
    this.$nextTick(() => {
      categoryIndex().then((response) => {
        const {
          data: {
            data: msgData = []
          }
        } = response
        this.categoryData = msgData
      })
    })
  },
  data() {
    return {
      categoryData: [],
      category_array: [],
      myProps: {
        value: 'category_id',
        label: 'name',
        children: 'child'
      },
      tableFormatData: {
        current: 'recycleTable',
        recycleTable: {
          key: 'recycleTable',
          api: {
            getList: goodsRecovery,
            delList: goodsRegainDel,
            msgConfig: {
              del: {
                type: 'warning',
                msg: '此操作会删除商品的所有数据，商品如有正在交易的订单、金额，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
              }
            }
          },
          tableData: [],
          files: {
            goods_name: '',
            category_id: '',
            ids: [],
            checkall: '0',
            Recycle: '0',
            redirect: 'goods_id'
          },
          change: {
            restore: {
              name: '恢复',
              key: 'restore',
              api: goodsRegain
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    categoryChange(category_array) {
      const [category_id] = category_array.slice(-1)
      this.tableFormatData.recycleTable.files.category_id = category_id
    }
  }
}
</script>

<style lang="scss" scoped>
.recycle-merchandise {
    .logo {
        height: 32px;
        width: 32px;
        border-radius: 32px;
        vertical-align: middle;
    }
}
</style>
